{extend name="base" /}
{block name="resources"/}
<link rel="stylesheet" href="SHOP_CSS/order_detail.css"/>
<link rel="stylesheet" href="SHOP_CSS/package.css"/>
<style>
    .logistics-operation{
        padding-left: 25px;
        padding-bottom: 25px;
    }
</style>

{/block}
{block name="main"}
<div class="order-detail">
    <div class="layui-row layui-col-space1 order-detail-info" >
        <div class="layui-col-md4 order-detail-left" >
            <div class="layui-card">
                <div class="layui-card-header nav-title">订单信息</div>
                <div class="layui-card-body">
                    <div class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label">订单编号：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">{$order_detail['order_no']}
                                        <a type="button" class="layui-btn layui-btn-xs layui-btn-primary"
                                           href="javascript:printDeliverOrder({$order_detail['order_id']});">打印发货单</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">订单类型：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">{$order_detail['order_type_name']}</div>
                                </div>

                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">订单来源：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">
                                        <p>{$order_detail.order_from_name}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">付款方式：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">{$order_detail.pay_type_name}</div>
                                </div>

                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">买家：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux"><a class="ns-text-color" target="_blank" href='{:addon_url("shop/member/editmember?member_id=".$order_detail["member_id"])}'>{$order_detail.nickname}</a></div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item order-detail-hr">

                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">配送方式：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">
                                        <p>{$order_detail['delivery_type_name']}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">收货人：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">
                                        <p>{$order_detail['name']}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">联系电话：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">
                                        <p>{$order_detail['mobile']}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">收货地址：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">
                                        <p>{$order_detail['full_address']}-{$order_detail['address']}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
						<div class="layui-form-item order-detail-hr">

						</div>
						<div class="layui-form-item">
						    <label class="layui-form-label">营销活动：</label>
						    <div class="layui-input-block">
						        <div class="layui-inline">
						            <div class="layui-form-mid layui-word-aux">
						                <p>{$order_detail['promotion_type_name']}</p>
						            </div>
						        </div>
						    </div>
						</div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">买家留言：</label>
                            <div class="layui-input-block">
                                <div class="layui-inline">
                                    <div class="layui-form-mid layui-word-aux">
                                        {if $order_detail['buyer_message'] == ""}
                                        <p>-</p>
                                        {else/}
                                        <p>{$order_detail['buyer_message']}</p>
                                        {/if}
                                    </div>
                                </div>
                            </div>
                        </div>

						<div class="layui-form-item">
						    <label class="layui-form-label">备注：</label>
						    <div class="layui-input-block">
						        <div class="layui-inline">
						            <div class="layui-form-mid layui-word-aux">
						                {if $order_detail['remark'] == ""}
						                <p>-</p>
						                {else/}
						                <p>{$order_detail['remark']}</p>
						                {/if}
						            </div>
						        </div>
						    </div>
						</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md8 order-detail-operation">
            <div class="layui-card">
                <div class="layui-card-header">订单状态：{$order_detail.order_status_name}</div>
                <div class="layui-card-body">
                    <p class="order-detail-tips"></p>

                    <button class="layui-btn ns-bg-color" onclick="orderRemark('{$order_detail.order_id}')" >备注</button>
                    {php}
                    $order_json_data = json_decode($order_detail['order_status_action'], true);
                    $action = $order_json_data['action'];
                    {/php}
                    {foreach $action as $action_k => $action_item}
                    <a class="layui-btn ns-bg-color" href="javascript:orderAction('{$action_item.action}', '{$order_detail.order_id}')">{$action_item.title}</a>
                    {/foreach}
                    <br>
                    <i class="layui-icon  layui-icon-about"></i>
                </div>
            </div>
        </div>
        <div class="order-detail-dl">
            <dl>
                <dt>提醒：</dt>
                <dd>交易成功后，平台将把货款结算至你的店铺账户余额，你可申请提现；</dd>
                <dd>请及时关注你发出的包裹状态，确保能配送至买家手中；</dd>
                <dd>如果买家表示未收到货或者货物有问题，请及时联系买家积极处理，友好协商；</dd>
            </dl>
        </div>
    </div>
</div>
{if  $order_detail['is_invoice'] == 1}
<div style="height: 15px;"></div>
<div class="layui-row ns-form invoice-view">

    <div class="layui-col-md6">
        <h4 class="invoice-title">发票信息</h4>
        <ul class="invoice-box">
            <li class="invoice-item">
                <label class="invoice-label">发票类型：</label>
                <div class="invoice-content">{if $order_detail['invoice_type'] == 1}纸质{else/}电子{/if}{if $order_detail['is_tax_invoice'] == 1}专票{else/}普票{/if}</div>
            </li>

            <li class="invoice-item">
                <label class="invoice-label">发票抬头：</label>
                <div class="invoice-content">{$order_detail['invoice_title']}</div>
            </li>
            <li class="invoice-item">
                <label class="invoice-label">发票抬头类型：</label>
                <div class="invoice-content">{$order_detail['invoice_title_type'] == 1 ? '个人' : '企业'}</div>
            </li>
            {if $order_detail['invoice_title_type'] == 2}
            <li class="invoice-item">
                <label class="invoice-label">纳税人识别号：</label>
                <div class="invoice-content">{$order_detail['taxpayer_number']}</div>
            </li>
            {/if}
            <li class="invoice-item">
                <label class="invoice-label">发票内容：</label>
                <div class="invoice-content">{$order_detail['invoice_content']}</div>
            </li>

            {if $order_detail['invoice_type'] == 1}

            <li class="invoice-item">
                <label class="invoice-label">发票邮寄地址：</label>
                <div class="invoice-content">{$order_detail['invoice_full_address']}</div>
            </li>
            {else/}
            <li class="invoice-item">
                <label class="invoice-label">发票接收邮件：</label>
                <div class="invoice-content">{$order_detail['invoice_email']}</div>
            </li>

            {/if}
        </ul>

    </div>
    <div class="layui-col-md6">
        <h4 class="invoice-title">发票费用</h4>
        <ul class="invoice-box">
            <li class="invoice-item">
                <label class="invoice-label">发票费用：</label>
                <div class="invoice-content"><span class="invoice-money">￥{$order_detail.invoice_money}</span> </div>
            </li>
            <li class="invoice-item">
                <label class="invoice-label">发票税率：</label>
                <div class="invoice-content"><span class="invoice-money">{$order_detail.invoice_rate}%</span> </div>
            </li>

            <li class="invoice-item">
                <label class="invoice-label">发票邮寄费用：</label>
                <div class="invoice-content"><span class="invoice-money">￥{$order_detail.invoice_delivery_money}</span> </div>
            </li>
        </ul>
    </div>
</div>
{/if}
<div style="height: 15px;"></div>

{if !empty($order_detail['package_list'])}
<!-- 物流信息 -->
<div class="layui-tab ns-table-tab">
    <ul class="layui-tab-title">
        {foreach $order_detail['package_list'] as $package_k => $package_v}
        <li {if $package_k == 0}class="layui-this"{/if}>{$package_v.package_name}</li>
        {/foreach}
    </ul>
    <div class="layui-tab-content" style="border: 1px solid #e6e6e6;background-color: #FFF;margin-top:10px;">
        {foreach $order_detail['package_list'] as $package_k => $package_v}
        <div class="layui-tab-item{if $package_k == 0} layui-show{/if}">
            <div class="package-inner">
                <div class="package-inner-content">
                    <div class="package-inner-content-item">
                        <label class="package-inner-content-item-label">发货时间：</label>
                        <div class="package-inner-content-item-label-value">
                            {:time_to_date($package_v["delivery_time"])}
                        </div>
                    </div>
                    <div class="package-inner-content-item">
                        <label class="package-inner-content-item-label">物流公司：</label>
                        <div class="package-inner-content-item-label-value">
                            <div>
                                {$package_v.express_company_name}
                            </div>
                        </div>
                    </div>
                    <div class="package-inner-content-item">
                        <label class="package-inner-content-item-label">运单号：</label>
                        <div class="package-inner-content-item-label-value">
                            <div>
                                {$package_v.delivery_no}
                            </div>
                        </div>
                    </div>
                    <div class="package-inner-goods-box">
                        <div class="package-inner-goods-block" >
                            <div class="package-inner-goods-container">
                                <div class="package-inner-goods-list">
                                    {foreach $package_v['goods_list'] as $goods_k => $goods_v }
                                    <div class="package-inner-goods-item">
                                        <div class="package-inner-goods-item-inner">
                                            <!-- <img src="{:img($goods_v.sku_image,'small')}" alt="{:$goods_v.sku_name}" class="package-inner-goods-item-image"> -->
											<div class="package-inner-goods-item-image"><img src="{:img($goods_v.sku_image,'small')}"></div>
                                            <div class="package-inner-goods-item-info">
												<p class="package-inner-goods-item-name ns-multi-line-hiding" title="{:$goods_v.sku_name}">
													{:$goods_v.sku_name}
												</p>
												<p class="package-inner-goods-item-name">
													数量：{$goods_v.num}
												</p>
											</div>
                                        </div>
                                    </div>
                                    {/foreach}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="package-inner-express">
                    <div class="package-inner-content-item">
                        <label class="package-inner-content-item-label-">物流状态：</label>
                        <span class="package-inner-content-item-label-value">
                            {if $package_v.trace.success}
                                {$package_v.trace.status_name}
                            {else/}
                                {$package_v.trace.reason}
                            {/if}

                        </span>
                        {if $package_v.type == 'electronicsheet'}
                        <a onclick="printElectronicsheet({$package_v.order_id},{$package_v.template_id})" class="layui-btn ns-bg-color">重新打印电子面单</a>
                        {/if}
                    </div>

                    {if $package_v.trace.success}
                    <div class="package-inner-express-box">
                        <ul class="layui-timeline">
                            {foreach $package_v.trace.list as $trace_k => $trace_v}
                            <li class="layui-timeline-item">
                                <span class="time-circle layui-timeline-axis" style="background-color: #f38421;"></span>
                                <div class="layui-timeline-content layui-text">
                                    <div class="express-timeline-title">{$trace_v.datetime}</div>
                                    <p>
                                        {$trace_v.remark}
                                    </p>
                                </div>
                            </li>
                            {/foreach}
                        </ul>
                    </div>
                    {/if}
                </div>
            </div>
            {php}
            $packageV = json_encode($package_v);
            {/php}
            {if in_array($order_detail.order_status,[1,3])}
            <div class="logistics-operation">
                <button class="btn layui-btn-primary layui-btn" onclick="logisticsOperation('{$order_detail.order_id}','{$package_v.id}',{$packageV})">修改物流</button>
            </div>
            {/if}
        </div>
        {/foreach}
    </div>
</div>
{/if}

<div class="order-detail-table">
    <table class="layui-table" lay-filter="parse-table-order-product" lay-skin="line" lay-size="lg">
        <thead>
        <tr>
            <th lay-data="{field:'product_name', width:200}">商品</th>
            <th lay-data="{field:'price'}">价格</th>
            <th lay-data="{field:'sale_num'}">数量</th>
            <th lay-data="{field:'total_money'}">小计（元）</th>
            <th lay-data="{field:'refund_status'}">退款状态</th>
            <th lay-data="{field:'shipping_status'}">状态</th>
        </tr>
        </thead>
        <tbody>

        {foreach $order_detail['order_goods'] as $list_k => $order_goods_item}
        <tr>
            <td>{$order_goods_item.sku_name}</td>
            <td>{$order_goods_item.price}</td>
            <td>{$order_goods_item.num}</td>
            <td>{$order_goods_item.goods_money}</td>
            <td>
                {if $order_goods_item.refund_status != 0}
                <a class="ns-text-color" href='{:addon_url("shop/orderrefund/detail?order_goods_id=".$order_goods_item["order_goods_id"])}'>{$order_goods_item.refund_status_name}</a>
                {/if}
            </td>
            <td>
                {$order_goods_item.delivery_status_name}
            </td>
        </tr>
        {/foreach}

        </tbody>
    </table>

    <div class="layui-row order-detail-total">
        <div class="layui-col-md9">
&nbsp;
        </div>
        <div class="layui-col-md3 order-money-box" >
            <div>商品总额：￥{$order_detail["goods_money"]}</div>
            <div>店铺优惠券：￥{$order_detail["coupon_money"]}</div>
            <div>店铺优惠：￥{$order_detail["promotion_money"]}</div>
            {if $order_detail["point_money"] > 0}<div>积分抵扣：￥{$order_detail["point_money"]}</div>{/if}
            <div>订单调价：￥{$order_detail["adjust_money"]}</div>
            <div>配送费用：￥{$order_detail["delivery_money"]}</div>
            <div>发票费用：￥{$order_detail["invoice_money"]}</div>
            <div>发票邮寄费用：￥{$order_detail["invoice_delivery_money"]}</div>
            <div>订单共{$order_detail["goods_num"]}件商品，总计：<span>￥{$order_detail["order_money"]}</span></div>
        </div>
    </div>
</div>

{include file="order/order_common_action" /}
<!-- 修改订单收货地址 -->
{include file="order/order_action" /}
<!-- 发货 -->
{include file="order/order_delivery_action" /}
{/block}
{block name="script"}
<script src="SHOP_JS/lodop_funcs.js"></script>

<script>

    var LODOP; //声明为全局变量
    function expressSheet(html){
        LODOP=getLodop();
        LODOP.PRINT_INIT("打印电子面单");
        LODOP.ADD_PRINT_HTM(0,10,"95%","100%",html);
//         LODOP.PREVIEW(); //预览
        LODOP.PRINT();  //直接打印
    }

    /**
     * 打印电子面单
     */
    function printElectronicsheet(order_id,template_id)
    {
        $.ajax({
            type: 'post',
            url: ns.url("shop/delivery/printelectronicsheet"),
            dataType: 'JSON',
            data:{
                order_id:order_id,
                template_id:template_id
            },
            success: function(res) {
                layer.msg(res.message);
                if (res.code >= 0){
                    expressSheet(res.data.PrintTemplate);
                }
            }
        });
    }


    function logisticsOperation(orderId,packageId,dataJson) {
        // console.log(dataJson);
        //获取模板
        var getTpl = $("#logistics_html").html();
        var data = {};
        data.dataJson = dataJson;
        $.ajax({
            type: "post",
            url: ns.url("shop/express/getShopExpressCompanyList"),
            dataType: 'json',
            async: false,
            success: function (res) {
                if (res.code == 0) {
                    data.express_company = res.data;
                }
            }
        });

        laytpl(getTpl).render(data, function (html) {
            layer.open({
                type: 1,
                shadeClose: true,
                shade: 0.3,
                fixed: false,
                scrollbar: false,
                title: "修改物流信息",
                area: '800px',
                content: html,
                cancel: function (index, layero) {
                    //右上角关闭回调
                    layer.close(index);
                    //return false 开启该代码可禁止点击该按钮关闭
                },
                success: function (layero, index) {
                    form.render();
                    form.on('radio(delivery_type)', function (data) {
                        if (data.value == 1) {
                            $(".express-type").removeClass("layui-hide");
                        } else {
                            $(".express-type").addClass("layui-hide");
                        }

                    });


                    form.on('submit(button_logistics_order)', function (data) {
                        var express_company_id = data.field.express_company_id;

                        if (data.field.delivery_type == 1 && express_company_id <= 0) {
                            layer.msg('请选择物流公司', {time: 2000, icon: 5});
                            return;
                        }


                        if (data.field.delivery_no == "" && data.field.delivery_type == 1) {
                            layer.msg('物流单号不能为空', {time: 2000, icon: 5});
                            return;
                        }

                        if (submitting) {
                            return false;
                        }
                        submitting = true;
                        data.field.order_id = orderId;
                        data.field.package_id = packageId;
                        $.ajax({
                            type: "post",
                            url: '{:addon_url("shop/delivery/editOrderDelivery")}',
                            async: true,
                            dataType: 'json',
                            data: data.field,
                            success: function (res) {
                                layer.msg(res.message, {}, function () {
                                    if (res.code == 0) {
                                        location.reload();
                                    } else {
                                        submitting = false;
                                    }
                                });
                            }
                        })
                    });

                }

            });
        })
    }
</script>
<!--发送订单弹出框-->
<script type="text/html" id="logistics_html">
    <div class="order-delivery">
        <div class="layui-form">
            <input type="hidden" name="type" value="manual">
            <div class="layui-form-item delivery-type">
                <label class="layui-form-label">发货方式：</label>
                <div class="layui-input-block">
                    {{# if(d.dataJson.delivery_type == 1){ }}
                    <input type="radio" lay-filter="delivery_type" name="delivery_type" value="1" title="物流发货" checked>
                    <input type="radio" lay-filter="delivery_type" name="delivery_type" value="0" title='无需物流'>
                    {{# }else{ }}
                    <input type="radio" lay-filter="delivery_type" name="delivery_type" value="1" title="物流发货">
                    <input type="radio" lay-filter="delivery_type" name="delivery_type" value="0" title='无需物流' checked>
                    {{# } }}
                </div>
            </div>

            {{# if(d.dataJson.delivery_type == 1){ }}
            <div class="express-type">
            {{# }else{ }}
            <div class="express-type layui-hide">
            {{# } }}
                <div class="layui-form-item logistics-company">
                    <label class="layui-form-label">物流公司：</label>
                    <div class="layui-input-block ns-len-mid">
                        <select name="express_company_id" lay-search lay-filter="express_company">
                            <option value="">请选择物流公司</option>
                            {{# layui.each(d.express_company, function(index, item){ }}
                                {{# if(item.company_id == d.dataJson.express_company_id){ }}
                                <option value="{{ item.company_id }}" selected>{{ item.company_name }}</option>
                                {{# }else{ }}
                                <option value="{{ item.company_id }}">{{ item.company_name }}</option>
                                {{# } }}
                            {{# }); }}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item express-number">
                    <label class="layui-form-label">快递单号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="delivery_no" placeholder="" autocomplete="off" class="layui-input ns-len-mid" value="{{d.dataJson.delivery_no}}">
                    </div>
                </div>
            </div>

            <div class="ns-form-row">
                <button type="button" class="layui-btn ns-bg-color" lay-submit lay-filter="button_logistics_order">保存</button>
            </div>
        </div>
    </div>
</script>
{/block}